// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.core.skinnedmodel;

import java.util.ArrayList;
import zombie.iso.IsoDirections;

public final class CharacterTextures {
    final ArrayList<CharacterTextures.CTAnimSet> m_animSets = new ArrayList();

    CharacterTextures.CTAnimSet getAnimSet(String string) {
        for (int _int = 0; _int < this.m_animSets.size(); _int++) {
            CharacterTextures.CTAnimSet cTAnimSet = (CharacterTextures.CTAnimSet)this.m_animSets.get(_int);
            if (cTAnimSet.m_name.equals(string)) {
                return cTAnimSet;
            }
        }

        return null;
    }

    DeadBodyAtlas.BodyTexture getTexture(String string0, String string1, IsoDirections isoDirections, int _int) {
        CharacterTextures.CTAnimSet cTAnimSet = this.getAnimSet(string0);
        if (cTAnimSet == null) {
            return null;
        } else {
            CharacterTextures.CTState cTState = cTAnimSet.getState(string1);
            if (cTState == null) {
                return null;
            } else {
                CharacterTextures.CTEntry cTEntry = cTState.getEntry(isoDirections, _int);
                return cTEntry == null ? null : cTEntry.m_texture;
            }
        }
    }

    void addTexture(String string0, String string1, IsoDirections isoDirections, int _int, DeadBodyAtlas.BodyTexture bodyTexture) {
        CharacterTextures.CTAnimSet cTAnimSet = this.getAnimSet(string0);
        if (cTAnimSet == null) {
            cTAnimSet = new CharacterTextures.CTAnimSet();
            cTAnimSet.m_name = string0;
            this.m_animSets.add(cTAnimSet);
        }

        cTAnimSet.addEntry(string1, isoDirections, _int, bodyTexture);
    }

    void clear() {
        this.m_animSets.clear();
    }

    private static final class CTAnimSet {
        String m_name;
        final ArrayList<CharacterTextures.CTState> m_states = new ArrayList();

        CharacterTextures.CTState getState(String string) {
            for (int _int = 0; _int < this.m_states.size(); _int++) {
                CharacterTextures.CTState cTState = (CharacterTextures.CTState)this.m_states.get(_int);
                if (cTState.m_name.equals(string)) {
                    return cTState;
                }
            }

            return null;
        }

        void addEntry(String string, IsoDirections isoDirections, int _int, DeadBodyAtlas.BodyTexture bodyTexture) {
            CharacterTextures.CTState cTState = this.getState(string);
            if (cTState == null) {
                cTState = new CharacterTextures.CTState();
                cTState.m_name = string;
                this.m_states.add(cTState);
            }

            cTState.addEntry(isoDirections, _int, bodyTexture);
        }
    }

    private static final class CTEntry {
        int m_frame;
        DeadBodyAtlas.BodyTexture m_texture;
    }

    private static final class CTEntryList extends ArrayList<CharacterTextures.CTEntry> {
    }

    private static final class CTState {
        String m_name;
        final CharacterTextures.CTEntryList[] m_entries = new CharacterTextures.CTEntryList[IsoDirections.values().length];

        CTState() {
            for (int _int = 0; _int < this.m_entries.length; _int++) {
                this.m_entries[_int] = new CharacterTextures.CTEntryList();
            }
        }

        CharacterTextures.CTEntry getEntry(IsoDirections isoDirections, int int1) {
            CharacterTextures.CTEntryList cTEntryList = this.m_entries[isoDirections.index()];

            for (int int0 = 0; int0 < cTEntryList.size(); int0++) {
                CharacterTextures.CTEntry cTEntry = (CharacterTextures.CTEntry)cTEntryList.get(int0);
                if (cTEntry.m_frame == int1) {
                    return cTEntry;
                }
            }

            return null;
        }

        void addEntry(IsoDirections isoDirections, int _int, DeadBodyAtlas.BodyTexture bodyTexture) {
            CharacterTextures.CTEntryList cTEntryList = this.m_entries[isoDirections.index()];
            CharacterTextures.CTEntry cTEntry = new CharacterTextures.CTEntry();
            cTEntry.m_frame = _int;
            cTEntry.m_texture = bodyTexture;
            cTEntryList.add(cTEntry);
        }
    }
}
